import 'dart:io';
import 'dart:ui';

import 'package:hive/hive.dart';
import 'package:test2/model/scene.dart';
import 'package:test2/util/PicUtil.dart';
part 'map.g.dart';

@HiveType(typeId: 2)
class MapC  extends HiveObject{
  @HiveField(0)
  String tip;

  @HiveField(1)
  String pic;

  @HiveField(2)
  bool top;

  MapC({
    required this.tip,
    required this.pic,
    required this.top,
  });

  void deletePic() {
    print("delete " + pic);

    File oldFile = File(PicUtil.picRootPath + pic);
    if (oldFile.existsSync()) {
      oldFile.delete();
    }
  }

  Future deleteSelf() async {

    String boxName = box?.name??"";
    if(boxName.isEmpty){
      return;
    }
    
    deletePic();
    
    Box<SceneC> boxScene = await Hive.openBox<SceneC>("${boxName}map$key");
    List<SceneC> test = boxScene.values.toList();
    for (SceneC item in boxScene.values) {
      await item.deleteSelf();
    }
    
    await delete();
  }
}
